//
//  ClassHeaderView.swift
//  scfriend
//
//  Created by wulanzhou on 2017/7/25.
//  Copyright © 2017年 wulanzhou. All rights reserved.
//

import UIKit

class ClassHeaderView: UIView {

    //MAKE:懒加载
    private lazy var imageView:UIImageView = {
    
        let img:UIImage = UIImage.init(named: "class_head_cell")!
        let imgView:UIImageView = UIImageView.init(frame: CGRect(x: 10, y: (self.bottomView.y - img.size.height)/2.0, width: img.size.width, height: img.size.height))
        imgView.image = img
        
        return imgView
    
    }()
    
    private lazy var labTitle:UILabel = {
    
        let lab:UILabel = UILabel.init(frame: CGRect(x: self.imageView.frame.maxX + 9, y: self.imageView.y, width: self.width - 20 - (self.imageView.frame.maxX + 9), height: self.imageView.height))
        lab.font = UIFont.systemFont(ofSize: 14.0)
        lab.textColor = UIColor.withRGBA(153, 153, 153)
        
        return lab
    
    }()
    
    //闭包
    typealias ClassSectionSettingClickBlock = () -> ()
    var sectionSettingClick:ClassSectionSettingClickBlock?
    
    @objc fileprivate func btnClick(sender:UIButton){
        self.sectionSettingClick?()
    }
    
    private lazy var setBtn:UIButton = {
    
        let btn:UIButton = UIButton.init(type: .custom)
        btn.frame = CGRect(x: self.width - 60, y: (self.bottomView.y - 30)/2.0, width: 50, height: 30)
        btn.setTitle("设置", for: .normal)
        btn.setTitleColor(UIColor.withRGBA(42, 173, 240), for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14.0)
        btn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
        return btn
    
    }()
    
    
    
    
    
    private lazy var bottomView:UIView = {
    
        let bgView:UIView = UIView.init(frame: CGRect(x: 0, y: self.height - 10, width: self.width, height: 10))
        bgView.backgroundColor = UIColor.withHex(hexString: "f0f0f0")
        return bgView
    
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        self.addSubview(self.imageView)
        self.addSubview(self.labTitle)
        self.addSubview(self.setBtn)
        self.addSubview(self.bottomView)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MAKE：公有方法
    func setTitle(title:String) {
        
        let size = title.textSize(font: self.labTitle.font, maxWidth: setBtn.x - self.labTitle.x)
        self.labTitle.text = title
        self.labTitle.width = size.width
        
    }
    
    

}
